// 当画布缩放的时候 等比例去滚动到相应的位置
$.extend({ canvasScaleTranslate: {} });
$.extend($.canvasScaleTranslate, {
  scrollTo: function (zoom) {
    var scrollWidthHalf = canvasWidth / 2;
    var scrollHeightHalf = canvasHeight / 2;
    if (zoom == 1) {
      window.scrollTo(canvasWidth / 2, canvasHeight / 2);
    } else if (zoom > 1) {
      var zoomScale = zoom - 1;
      var translateLocation = (canvasWidth * zoomScale) / 2;
      window.scrollTo(scrollWidthHalf - translateLocation, scrollHeightHalf - translateLocation);
    } else {
      var zoomScale = 1 - zoom;
      var translateLocation = Math.ceil((canvasWidth * zoomScale) / 2);
      window.scrollTo(scrollWidthHalf + translateLocation, scrollHeightHalf + translateLocation);
    }
  },
  scrollToByFirstFigure(zoom) {
    var zoom = zoom || 1;
    let id = $.tabComp.getTabSelectLayid();

    console.log("[ id ] >", id);
    try {
      var context = window.app.getContext();
      var activeEditor = context.getActiveEditor();
      var figure = activeEditor.rootEditPart.figure;
      var firstFigure = figure.figures.data[0];
      let { width, height } = firstFigure;
      console.log("[firstFigure  ] >", firstFigure);
      if (id === "firstPage") {
        var typeName = firstFigure.properties.modelProperty.typeName;
        if (typeName === "TextModelJson") {
          var canvasViewHalfWidth = window.innerWidth / 2 - width / 2;
          var canvasViewHalfHeight = window.innerHeight / 10;
        } else {
          var canvasViewHalfWidth = window.innerWidth / 10;
          var canvasViewHalfHeight = window.innerHeight / 2 - height / 2;
        }
      } else {
        var canvasViewHalfWidth = window.innerWidth / 10;
        var canvasViewHalfHeight = window.innerHeight / 2 - height / 2;
      }

      window.scrollTo(firstFigure.x / zoom - canvasViewHalfWidth, firstFigure.y / zoom - canvasViewHalfHeight);
    } catch (error) {
      this.scrollTo(zoom);
    }
  },
});
